﻿/*
{
"状态":1,
"名称":"新增-部门资料",
"作者":"陈泽椿",
"创建时间":"2018-06-30",
"功能":"新增-部门资料",
"log": [
	{"date":"06-01" , "dev" :"hzhh" , "content" : ""}
]
}
*/
declare @company_key int ,@department_id varchar(100) , @department_name varchar(100) , @remarks varchar(100) , @father_key int
set @company_key = '{company_key}'
set @department_id ='{department_id}' 
set @department_name = '{department_name}'
set @remarks = '{remarks}'
set @father_key = '{father_key}'



--校验信息
if isnull(@department_id,'')=''
begin 
	RAISERROR ('SQL:不么部门id不允许为空', 16 ,1 ) ; 
	return 
end 


if isnull(@department_name,'')=''
begin 
	RAISERROR ('SQL:部门名称不允许为空', 16 ,1 ) ; 
	return 
end 


if EXISTS(SELECT * FROM b_department WHERE [department_id]=@department_id )
begin
	RAISERROR ('SQL:部门id已经存在', 16 ,1 ) ; 
	return 
end

INSERT INTO [dbo].[b_department]([company_key],[department_id],[father_key],[department_name],[remarks],[create_time],[update_time])
VALUES( @company_key  , @department_id ,@father_key, @department_name, @remarks , getdate(), getdate() )

